// Created by Windward Studios - no copyright is claimed. This code can be used in
// any manner by anyone for any reason. There is no copyright of any kind on it. You may
// use it in commercial products. You may change it without sharing those changes.
// We ask that you keep the "created by Windward Studios" in a comment at the top.

using System;
using System.Collections.ObjectModel;
using System.Data;

namespace net.windward.utils.ado
{
	/// <summary>
	/// A Stored procedure.
	/// </summary>
	public class WrStoredProcedure : WrDbElement
	{

		private readonly DbType returnType;
		private readonly bool hasReturnValue;
		private readonly bool isSystem;
		private readonly WrProcParam[] parameters;

		/// <summary>
		/// Create a stored procedure object.
		/// </summary>
		/// <param name="schema">The schema that owns this element. null if none, empty string if default and the default has no name.</param>
		/// <param name="name">The name of the table.</param>
		/// <param name="description">The description (metadata) of the table.</param>
		/// <param name="isSystem">True if a system table.</param>
		/// <param name="parameters">The parameters for this procedure.</param>
		public WrStoredProcedure(string schema, string name, string description, bool isSystem, WrProcParam[] parameters)
			: base(schema, name, description)
		{
			this.isSystem = isSystem;
			hasReturnValue = false;
			this.parameters = parameters;
		}

		/// <summary>
		/// Create a stored procedure object.
		/// </summary>
		/// <param name="schema">The schema that owns this element. null if none, empty string if default and the default has no name.</param>
		/// <param name="name">The name of the table.</param>
		/// <param name="description">The description (metadata) of the table.</param>
		/// <param name="returnType">The DbType that is returned by this procedure.</param>
		/// <param name="isSystem">True if a system table.</param>
		/// <param name="parameters">The parameters for this procedure.</param>
		public WrStoredProcedure(string schema, string name, string description, DbType returnType, bool isSystem, WrProcParam[] parameters)
			: base(schema, name, description)
		{
			this.isSystem = isSystem;
			hasReturnValue = true;
			this.returnType = returnType;
			this.parameters = parameters;
		}

		/// <summary>
		/// True if this is a system table or view.
		/// </summary>
		public virtual bool IsSystem
		{
			get { return isSystem; }
		}

		/// <summary>
		/// The data type of the returned value.
		/// </summary>
		public DbType ReturnType
		{
			get { return returnType; }
		}

		/// <summary>
		/// true if returns a value.
		/// </summary>
		public bool HasReturnValue
		{
			get { return hasReturnValue; }
		}

		/// <summary>
		/// Return all parameters in a stored procedure.
		/// </summary>
		public WrProcParam[] Parameters
		{
			get { return parameters; }
		}
	}

	/// <summary>
	/// A collection of stored procedures.
	/// </summary>
	public class WrStoredProcedureCollection : Collection<WrStoredProcedure>
	{
	}
}
